<template>
  <a-modal
    v-model:visible="preview"
    :title="title"
    :footer="null"
    width="300"
    :maskClosable="true"
  >
    <div class="content">
      <a-upload
        v-model:file-list="fileList"
        name="file"
        :showUploadList="false"
        :customRequest="(e) => customRequest(e, path)"
      >
        <a-button type="primary" size="middle">
          <cloud-upload-outlined />上传
        </a-button>
      </a-upload>
    </div>
  </a-modal>
</template>
<script>
import { ipcApiRoute, specialIpcRoute } from "@/utils/ipcMainApi";
import {
  getCourseListDetil,
  uploadRecordingStatus,
  getClientComment,
} from "@/api/course.js";
import { uploadVideo } from "@/api/file.js";

import "../../../utils/hls";

import { ipc } from "@/utils/ipcRenderer";
import Player from "xgplayer";
import { toRaw } from "vue";
//引入fs模块
const fs = require("fs");
import { createStream, createRecorder } from "electron-webrtc";
import { saveAs } from "file-saver"; // 用于保存文件

import axios from "axios";
export default {
  components: {},
  data() {
    return {
      preview: false,
      title: "上传",
      fileList: [],
      imageUrl: "",
      businessId: 1,
      time: 1,
    };
  },
  created() {},
  mounted() {},
  computed: {},
  methods: {
    show(item) {
      this.preview = true;
      this.businessId = item.id;
    },
    handleChange() {},
    beforeUpload() {},

    customRequest(options, path) {
      var video = document.createElement("video");
      video.src = path;
      video.preload = "metadata";
      video.onloadedmetadata = function () {
        this.time = video.duration;
        console.log(this.time, "this.time");
      };

      const formData = new FormData();
      formData.append("macAddress", localStorage.getItem("macAddress"));
      formData.append("businessId", this.businessId);
      formData.append("businessType", 1);
      formData.append("fileType", 1);
      formData.append("videoLength", this.time);
      formData.append("videoFile", options.fileItem.file);
      uploadVideo(formData).then((response) => {
        if (response.code === 200) {
          this.$message.success("上传成功，AI分析报告生成中！");
        } else {
          this.$message.error("上传失败：" + response.message);
        }
      }).catch((error) => {
        console.error("上传错误：", error);
        this.$message.error("上传过程中发生错误，请重试。");
        
      });
    },
  },
};
</script>
<style lang="less" scoped>
.content {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>
